﻿// On définit la constante de compilation conditionnelle MYSQL.
#define MYSQL


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using INSTA.BankApplication.DAL;


#if MYSQL
using MySql.Data.MySqlClient;
#endif


namespace INSTA.BankApplication.DAL
{
    public class MySqlDbAccessor : AbstractDbAccessor
    {
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="mappedObject">The mapped object.</param>
        public MySqlDbAccessor(DataMapper mappedObject, string connectionString) : base(mappedObject, connectionString)
        {
            // On instancie le bon type de générateur SQL
            // pour ce DbAccessor..
            SqlGenerator = new MySqlSqlGenerator(mappedObject);

        }

#if MYSQL

        protected override void InitTypedDatabaseObjects()
        {
            Connection  = GetNewConnection();
            Command     = GetNewCommand();
            Adapter     = new MySqlDataAdapter();
        }
        
        protected override IDbConnection GetNewConnection()
        {
            return new MySqlConnection();
        }

        protected override IDbCommand GetNewCommand()
        {
            return new MySqlCommand();
        }
#else

        /// <summary>
        /// Inits the strongly-typed db objects
        /// (for Sql Server, or My Sql).
        /// </summary>
        protected override void InitTypedDatabaseObjects()
        {

        }

        protected override IDbConnection newConnection()
        {
            return null;
        }

        protected override IDbCommand newCommand()
        {
            return null;
        }

#endif
    

    }
}